package simple.charlie.hibernate.student.services;

import java.util.Collection;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import simple.charlie.hibernate.student.entities.Student;

@Service
@Transactional
public class StudentServices {

	@Autowired
	@Qualifier("studentSessionFactory")
	private SessionFactory sessionFactory;

	public void save(Student entity) {
		sessionFactory.getCurrentSession().persist(entity);
	}
	
	public Collection<Student> get(){
		Query query = sessionFactory.getCurrentSession().createQuery("select e from simple.charlie.hibernate.student.entities.Student as e");
		Collection<Student> list = query.list();
		return list;
	}
}
